package com.web.star.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

import com.web.star.eneity.TbRole;
import com.web.star.eneity.TbUser;
@Component
public class UserService implements UserDetailsService  {
	
	@Override
	public UserDetails loadUserByUsername(String username) 
			throws UsernameNotFoundException {
		TbUser user = new TbUser();
		user.setName("admin");
		BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
		user.setPassword(bCryptPasswordEncoder.encode("123456"));
		user.setEnabled(true);
		TbRole role = new TbRole();
		role.setId(1l);
		role.setName("ROLE_admin");
		List<TbRole> roleList = new ArrayList<>();
		roleList.add(role);
		user.setRoles(roleList);
		return user;
	}

}
